package com.ctsi.security.event.organ;

import com.ctsi.commons.event.AbstractObserver;
import com.ctsi.commons.event.BaseEvent;
import com.ctsi.framework.common.startrun.ComponentFactory;
import com.ctsi.organise.common.model.Organise;
import com.ctsi.organise.common.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;


@SuppressWarnings("unchecked")
public class OrganLeaveOrganEvent extends AbstractObserver {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4715730496557668799L;
	private static Logger logger = LoggerFactory.getLogger(OrganLeaveOrganEvent.class);
	private static OrganEventService organEventService;

	@Override
	public void onEvent(Object[] args) {
		// SRoleService sRoleService = (SRoleService)ComponentFactory.getApplicationContext().getBean("sRoleService");
		// sRoleService.refresh(null);

		logger.info("权限角色事件处理：组织结构组织离开组织");
		BaseEvent event = (BaseEvent) args[0];
		Organise organ = (Organise) event.getSource();
		if (args.length > 1) {
			List<Person> persons = (List<Person>) args[1];
			List<Organise> organs = (List<Organise>) args[2];
			organEventService = this.getOrganEventService();
			organEventService.organLeaveOrganEventWithRefresh(organ.getParentId(), organ.getPartyId(), organs, persons);
		}
	}

	private OrganEventService getOrganEventService() {
		if (organEventService == null) {
			organEventService = (OrganEventService) ComponentFactory.getApplicationContext().getBean("organEventService");
		}
		return organEventService;
	}
}
